package com.gift.recommendation.modules.user.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.Base.PageData;
import com.gift.recommendation.modules.user.biz.OrderBiz;
import com.gift.recommendation.modules.user.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/2/17
 */
@RestController
@RequestMapping("/gift/order")
@Api(tags = "订单管理")
@Validated
public class OrderController {

    @Autowired
    private OrderBiz orderBiz;

    @ApiOperation(value = "用户下订单")
    @RequestMapping(path = "/place-order",method = RequestMethod.POST)
    public BaseResponse placeOrder(@RequestBody OrderReq req){
        orderBiz.placeOrder(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查看订单列表")
    @RequestMapping(path = "/list-page",method = RequestMethod.POST)
    public BaseResponse<PageData<OrderRsp>> listOrderPage(@RequestBody OrderListReq req){
        PageData<OrderRsp> result = orderBiz.listOrderPage(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "商家发货")
    @RequestMapping(path = "/deliver",method = RequestMethod.POST)
    public BaseResponse deliver(@RequestBody OrderSendReq req){
        orderBiz.deliver(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查看快递信息")
    @RequestMapping(path = "/show-express",method = RequestMethod.POST)
    public BaseResponse showExpress(@RequestBody OrderMessageReq req){
        OrderExpressRsp result = orderBiz.showExpress(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "确认收货")
    @RequestMapping(path = "/confirm-order",method = RequestMethod.POST)
    public BaseResponse confirmOrder(@RequestBody OrderMessageReq req){
        orderBiz.confirmOrder(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "获取快递公司")
    @RequestMapping(path = "/express-company",method = RequestMethod.GET)
    public BaseResponse expressCompany(){
        List<ExpressCompanyRsp> result = orderBiz.expressCompany();
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "库存校验")
    @RequestMapping(path = "/check-storage",method = RequestMethod.POST)
    public BaseResponse checkStorage(@RequestBody CheckStorageReq req){
        CheckStorageRsp result = orderBiz.checkStorage(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "撤销订单")
    @RequestMapping(path = "/cancle-order",method = RequestMethod.POST)
    public BaseResponse cancelOrder(@RequestBody CancelOrderReq req){
          orderBiz.cancelOrder(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查看撤销原因")
    @RequestMapping(path = "/show-cancel",method = RequestMethod.POST)
    public BaseResponse showCancelOrder(@RequestBody ShowCancelOrderReq req){
        ShowCancelOrderRsp result = orderBiz.showCancelOrder(req);
        return BaseResponse.success(result);
    };
}
